/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-13 17:25:35
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-26 13:44:18
 * @FilePath: /yt-devops/lib/pages/devices/device_tab/device_detail/business_electricity_storage_device_detail/business_electricity_storage_device_detail_model.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:dart_date/dart_date.dart';
import 'package:yt_devops/utils/constants/time_formated.dart';
import 'package:yt_devops/utils/enums.dart';

/// 充放电功率
class PowerCurveModel {
  PowerCurveModel({
    this.doubleVal,
    this.eventTs,
    this.id,
    this.siteId,
    this.type,
  });

  ///功率值，示例：0
  double? doubleVal;

  ///数据上报时间，示例：2023-07-24 14:04:00
  String? eventTs;

  ///单元id，示例：null
  int? id;

  ///站点id，示例：null
  int? siteId;

  ///时间维度  0日 1月 2年 3总
  int? type;

  String get getHourAndMinute {
    if (eventTs == null) {
      return '';
    } else {
      return eventTs!.substring(11, 16);
    }
  }

  factory PowerCurveModel.fromMap(Map<String, dynamic> json) => PowerCurveModel(
        doubleVal: json['doubleVal'],
        eventTs: json['eventTs'],
        id: json['id'],
        siteId: json['siteId'],
        type: json['type'],
      );
}

/// 充放电趋势
class PowerTrendModel {
  PowerTrendModel({
    this.doubleVal,
    this.eventTs,
  });

  ///功率值，示例：0
  double? doubleVal;

  ///数据上报时间，示例：2023-07-24 14:04:00
  String? eventTs;

  String getTimeLabel(StatisticUnitStatusType timeType) {
    if (eventTs == null) {
      return '';
    } else {
      switch (timeType) {
        case StatisticUnitStatusType.day:
          return eventTs!.substring(11, 16);
        case StatisticUnitStatusType.month:
          return eventTs!.substring(5, 10);
        case StatisticUnitStatusType.year:
          return eventTs!.substring(5, 7);
        case StatisticUnitStatusType.accumulate:
          return eventTs!.substring(0, 4);
      }
    }
  }

  factory PowerTrendModel.fromMap(Map<String, dynamic> json) => PowerTrendModel(
        doubleVal: json['doubleVal'],
        eventTs: json['eventTs'],
      );
}
